<?php
include "header.php";

require_once './libs/Page.class.php';


$sql_cnt = "SELECT id FROM  wish";
$result = $conn->query($sql_cnt);
$total_cnt = $result->num_rows;   // 符合条件的所有记录的总数。
$listRows = 5;                     // 每页的记录数量
$total_pages = ceil($total_cnt/$listRows);  // 11/5

 $Page = new Page($total_cnt,$listRows);


$page = empty($_GET['p']) ? 1 : $_GET['p'];  //0
$page = ($page < 1) ? 1 : $page;
$page = ($page > $total_pages) ? $total_pages : $page;

 
$sql = "SELECT * FROM  wish LIMIT ".($page-1)*$listRows . "  , ".$listRows;

$result = $conn->query($sql);

$arrlist = array();
if ($result->num_rows > 0) {  
    // 输出每行数据
    while($row = $result->fetch_assoc()) {
        array_push($arrlist, $row);        
    }
} 
$conn->close(); 
?>

<div id="right">
<?php 
    echo $sql;
?>	
<table border="1">
<tr>
<td>序号</td>
<td>留言者</td>
<td>留言内容</td>
<td>留言时间</td>
<td>操作</td>
</tr>
<?php foreach($arrlist as $vo){ ?>
<tr>
<td><?php echo $vo['id'];?></td>
<td><?php echo $vo['username'];?></td>
<td><?php echo $vo['content'];?></td>
<td><?php echo $vo['time_at'];?></td>
<td><span><a>修改</a></span><span><a>删除</a></span></td>
</tr>
<?php } ?>
</table>

    <div class="Pagination">
        <?php 
        echo $Page->showpage();
        /*
        $s = "";
        for($i=1;$i<=$total_pages;$i++){            
            $s .= "<span><a href='?p=$i'>$i</a></span>";
        }
        
        echo $s;
         * 
         */
        ?>
    </div>
    
</div>
include "footer.php";
